<?php

class AuthItemForm extends CFormModel
{
	public $name;
	public $description;
	public $type;
	public $bizRule;
	public $data;

	/**
	* Declares the validation rules.
	*/
	public function rules()
	{
		return array(
			array('name', 'cleanBlank'),
			array('name, type, description', 'required'),
		   	array('bizRule, data', 'safe'),
		);
	}

	public function attributeLabels()
	{
		return array(
			'name'			=> 'Name',
			'description'	=> 'Description',
			'bizRule'		=> 'Business rule',
			'data'			=> 'Data',
		);
	}
    
    public function cleanBlank($attribute, $params)
    {
        $this->$attribute = str_replace(' ', '_', trim($this->$attribute));
    }
    
    public function getTypeName()
    {
        if(CAuthItem::TYPE_OPERATION == $this->type)
            return 'Operation';
        elseif(CAuthItem::TYPE_TASK == $this->type)
            return 'Task';
        elseif(CAuthItem::TYPE_ROLE == $this->type)
            return 'Role';
        else
            throw new CException('Unknown type');
    }
}

